Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a few navigation shortcuts #61

Merged
merged 9 commits into from
Aug 9, 2024
Merged

Conversation

robtfm
Copy link
Contributor

@robtfm robtfm commented Aug 8, 2024

adds support for (configurable) word left/right and line start/end navigation.

i'm in the process of removing egui from my app, and text entry is the main blocker. to that end i hope to also add support for

  • copy/paste
  • multiline entry
  • selection hilighting
  • mouse interactions (though i suspect this won't be upstreamed easily)

i fully understand if you think this pr and these other features are out of scope of a "simple" text entry field though.

src/lib.rs Outdated Show resolved Hide resolved
@rparrett
Copy link
Owner

rparrett commented Aug 9, 2024

Cool. At a glance I feel like this fits in well. I'll take a closer look soon.

i fully understand if you think this pr and these other features are out of scope of a "simple" text entry field though.

Let me give that a bit amount of thought. The evolving "bevy development roadmap landscape" may have changed my thoughts a bit. cosmic-text may make some of those features less intense. But I still think there's a hard line at dependencies on crates that depend on Bevy.

@rparrett
Copy link
Owner

rparrett commented Aug 9, 2024

As implemented here, there's an issue where if e.g. KeyCode::KeyA and KeyCode::Home arrive on the same frame, the KeyCode::KeyA event is not processed.

But more generally, it's not possible to know which key arrived first unless we deal with a single stream of events. This sort of bug was my bane from Bevy versions 0.4 -> 0.13 when it finally became possible to fix it properly. So I would strongly prefer to do our processing on a single event stream. I think that a way around this might be to roughly:

  • Move event processing into a separate system scheduled before the current keyboard system.
  • Restructure TextInputNavigationBindings such that a key and modifier are stored separately
  • In the event processing code, I think it might be okay to rely on ButtonInput purely for the modifiers. But I haven't totally thought that through and tracking key press state probably wouldn't be too much trouble if we have to.
  • Make TextInputAction an Event and add CharLeft and CharRight and emit it when the key is pressed, if the necessary modifiers are in a pressed state
  • Rework the current keyboard system so that it reacts to those events

I am open to other ideas but I think that would even simplify things overall. We wouldn't need the manual event reader that was added in #58, for instance.

@robtfm
Copy link
Contributor Author

robtfm commented Aug 9, 2024

I guess having a primary button for the action would avoid moving twice if you hold right and press the modifier twice too. Ok let me try.

@robtfm
Copy link
Contributor Author

robtfm commented Aug 9, 2024

i added modifiers and moved the char left/right and backspace+delete into the enum.

i can make a separate system if you like, but i'm not sure the benefit is that much (and cloning the reader is super-cheap, it's just a usize)

@rparrett
Copy link
Owner

rparrett commented Aug 9, 2024

Looks great, thanks!

@rparrett rparrett merged commit be1d9bd into rparrett:main Aug 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants